// Tags: 
#include <cstdio>

const int N = 1e5 + 5;
int n, t;
char str[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("str.in", "r", stdin);
  freopen("str.out", "w", stdout);
#endif
#endif

  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    scanf("%s", str + 1);
    if (n == 1) {
      puts("1");
      continue;
    }
    int ans = 0, cnt = 0;
    str[n + 1] = 0;
    for (int i = 1; i <= n;) {
      if (!cnt && str[i] == str[i + 1]) {
        ++ans;
        while (str[i] == str[i + 1]) ++i;
      }
      while (cnt && str[i] == str[i + 1]) {
        cnt--, ans++;
        ++i;
      }
      if (str[i] != str[i + 1]) ++cnt, ++i;
    }
    ans += cnt >> 1;
    printf("%d\n", ans);
  }
  return 0;
}